

***************************************************
* Figure 5
***************************************************

use "$workdata/crime", clear

capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
g d=age_q>=25
g age_q0=age_q-25
g age_q0_2= age_q0^2
g age_q0_3= age_q0^3
g dXage_q0=d*age_q0
g dXage_q0_2=d*age_q0_2
g dXage_q0_3=d*age_q0_3

g h=1

local y = "charge_min"
local spec_num=1
if `spec_num'==1 local spec="d age_q0                   dXage_q0"
if `spec_num'==1 local spec_name="1st order polynomial spline"

reg `y' `spec' if age_q>=21 & age_q<29 & koen==1, vce(cluster pnr)
local beta_d_koen1=round(_b[d], .0001)*10000
local beta_d_koen1=floor(`beta_d_koen1')/100 
local se_d_koen1=round(_se[d], .00001)
capture drop yhat_koen1
predict yhat_koen1

reg `y' `spec' if age_q>=21 & age_q<29 & koen==2, vce(cluster pnr)
local beta_d_koen2=round(_b[d], .0001)*10000
local beta_d_koen2=floor(`beta_d_koen2')/100 
local se_d_koen2=round(_se[d], .00001)
capture drop yhat_koen2
predict yhat_koen2


preserve

local y = "charge_min"
collapse `y' yhat_koen1 yhat_koen2 sa_charge_until (sem) se=`y'  [aw=e] if age_q>=21 & age_q<29, by(age_q koen)
g `y'_min=`y'-se*1.96
g `y'_max=`y'+se*1.96

twoway (rarea `y'_min `y'_max age_q if age_q< 25 & koen==1, color(gs13)) ///
	   (rarea `y'_min `y'_max age_q if age_q>=25 & koen==1, color(gs13)) ///
	   (rarea `y'_min `y'_max age_q if age_q< 25 & koen==2, color(gs13)) ///
	   (rarea `y'_min `y'_max age_q if age_q>=25 & koen==2, color(gs13)) ///
	   (line yhat_koen1 age_q       if age_q< 25 & koen==1, lcolor(gs3)) ///
   	   (line yhat_koen1 age_q       if age_q>=25 & koen==1, lcolor(gs3)) ///
	   (line yhat_koen2 age_q       if age_q< 25 & koen==2, lcolor(gs3)) ///
   	   (line yhat_koen2 age_q       if age_q>=25 & koen==2, lcolor(gs3)) ///
	   (scatter `y' age_q           if age_q< 25 & koen==1, msymbol(o) mlcolor(gs3) mfcolor(gs12))  ///
	   (scatter `y' age_q           if age_q>=25 & koen==1, msymbol(o) mlcolor(gs3) mfcolor(gs12))  ///
	   (scatter `y' age_q           if age_q< 25 & koen==2, msymbol(o) mlcolor(gs3) mfcolor(gs16))  ///
	   (scatter `y' age_q           if age_q>=25 & koen==2, msymbol(o) mlcolor(gs3) mfcolor(gs16))  ///
	    , ylabel(0(0.005)0.03) ytitle("Share charges with a crime", height(5))  ///
	     xlabel(21(1)29)       xtitle("Age in months", height(5))      ///
	     xline(24.958333) scheme(s1mono) legend(order(9 "Men" 11 "Women")) ///
		 note("Effect size: Men: `beta_d_koen1' pp (`se_d_koen1'), Women: `beta_d_koen2' pp (`se_d_koen2')" "Standard errors in parenthesis, Specification: `spec_name'") ///
		 name(fig5, replace)
graph save fig5  $figures/fig5, replace
graph export $figures/fig5.pdf, name(fig5) replace
graph export $figures/fig5.png, name(fig5) replace


***************************************************
* end: Figure 5
***************************************************

